package com.karson.service.service.impl;

import com.karson.common.enums.StatisticType;
import com.karson.service.service.IStatisticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author ZKS
 */


@Component
public class StatisticFactory {
    private final Map<String, IStatisticService> strategies;

    public StatisticFactory(Map<String, IStatisticService> strategies) {
        this.strategies = strategies;
    }

    /**
     * 根据统计类型获取策略
     * @param typeEnum 统计类型枚举
     * @return 对应的 IStatisticService
     */
    public IStatisticService getStrategy(StatisticType typeEnum) {
        if (typeEnum == null) {
            throw new IllegalArgumentException("StatisticType cannot be null");
        }

        IStatisticService service = strategies.get(typeEnum.getType());
        if (service == null) {
            throw new IllegalArgumentException("No statistic service found for type: " + typeEnum);
        }
        return service;
    }
}
